Add AI binding support for pi - #123
Merged
Merged
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
Maximo-Guk
commented
Aug 10, 2026
Maximo-Guk
force-pushed
the
maximo/add-ai-binding-support-for-pi
branch
from
August 10, 2026 15:56
59cd827 to
595d66d
Compare
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
Member
|
Looks like upstream PR was merged, shall we update to use that? |
Member
Author
|
Just waiting on a PI release before we can use the upstreamed changes, I'll put up a PR to update once it gets released. The vendored transport changes in this PR are identical to what got merged in to PI, I would like to get this out so we can start battle testing what we upstreamed in to PI. |
Maximo-Guk
marked this pull request as draft
August 13, 2026 20:07
Member
Author
|
Drafting this for the time being as I work through on updating the PI implementation to be smarter & more efficient |
Maximo-Guk
force-pushed
the
maximo/add-ai-binding-support-for-pi
branch
from
August 14, 2026 14:51
595d66d to
24fbea1
Compare
This comment was marked as resolved.
This comment was marked as resolved.
Maximo-Guk
force-pushed
the
maximo/add-ai-binding-support-for-pi
branch
from
August 14, 2026 14:57
24fbea1 to
0672c92
Compare
This comment was marked as resolved.
This comment was marked as resolved.
Maximo-Guk
force-pushed
the
maximo/add-ai-binding-support-for-pi
branch
2 times, most recently
from
August 15, 2026 02:19
9b54ad4 to
f8704a2
Compare
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
Maximo-Guk
force-pushed
the
maximo/add-ai-binding-support-for-pi
branch
from
August 15, 2026 20:17
f8704a2 to
6f18507
Compare
This comment was marked as resolved.
This comment was marked as resolved.
Maximo-Guk
force-pushed
the
maximo/add-ai-binding-support-for-pi
branch
from
August 15, 2026 20:44
6f18507 to
976a0e7
Compare
This comment was marked as resolved.
This comment was marked as resolved.
Maximo-Guk
force-pushed
the
maximo/add-ai-binding-support-for-pi
branch
from
August 18, 2026 02:30
976a0e7 to
00d7293
Compare
|
@Maximo-Guk Bonk workflow failed. Check the logs for details. View workflow run · To retry, trigger Bonk again. |
Preview:
|
Member
Author
|
bonk break glass |
Maximo-Guk
force-pushed
the
maximo/add-ai-binding-support-for-pi
branch
from
August 18, 2026 02:42
00d7293 to
945eb5e
Compare
Maximo-Guk
marked this pull request as ready for review
August 18, 2026 02:51
ndisidore
reviewed
Aug 18, 2026
ndisidore
approved these changes
Aug 18, 2026
kentonv
reviewed
Aug 18, 2026
…E_BINDING opt-out
…ays rides the gateway
The WAI knobs existed because Workers AI originally ran on the account-local
WORKERS_AI binding, which can only name same-account gateways; a cross-account
CF_AI_GATEWAY (the internal production shape) therefore needed an escape
hatch. Workers AI has since moved to ordinary gateway routes
(.../{account}/{gateway}/workers-ai/v1), which work cross-account over
HTTPS+token exactly like anthropic/openai -- so the escape hatch no longer
pays for its config surface.
Binding-routed gateway traffic went through gateway().run(), the
universal endpoint's [{provider, endpoint, headers, query}] envelope,
which a vendored shim built by splicing the request body into a JSON
string. The gateway also serves its provider-native passthrough over the
AI binding at /ai-gateway/gateways/{gateway}/{provider}/... -- the HTTPS
path minus the account id, since the binding channel carries identity --
and that route accepts exactly the requests pi's API impls already
produce.
So there is nothing left to translate. Binding-routed models take the
binding host as their gateway root and pi's fetch option is the binding's
own fetch, unwrapped; the envelope, the splice, the JSON-object scanner
and the whole vendored ai-gateway-binding-fetch module go away. Method,
headers, query string and the body stream ride through untouched, so
multi-MB prompt bodies are never copied in the isolate.
Google keeps its HTTPS root automatically: `binding` is resolved per
provider, and bindingFor() returns undefined for google (its adapter
can't take a custom fetch). cf-aig-authorization now reaches the gateway,
which recognizes the pre-authentication sentinel and strips it.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Trim and lowercase the value once on each side, so a stray " False " opts out instead of reading as unset and silently picking the other transport. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Maximo-Guk
force-pushed
the
maximo/add-ai-binding-support-for-pi
branch
from
August 18, 2026 20:28
5acb819 to
200665a
Compare
kentonv
approved these changes
Aug 18, 2026
Member
Author
|
bonk break glass |
… Workers AI isn't recommended ( breaks toMarkDown() )
Maximo-Guk
force-pushed
the
maximo/add-ai-binding-support-for-pi
branch
from
August 18, 2026 20:58
200665a to
5c09db8
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why?
We want to enable users to use AI gateway without needing to provide an API token ( which puts them at risk of credential expiry, rotation, etc ) and makes them need to visit the dashboard just to provision a token during the deploy flow.
How?
Workers AI Gateway can now be accessed over the AI binding!
How was this tested?
You can test it with the updated deploy flow which is based off this branches head https://gadgets-deploy.gadgets-staging.workers.dev/deploy ( notice you don't need to provision an api token ), and also locally.